//
//  NSMutableAttributedString+Extension.swift
//  SwiftProject
//
//  Created by qindong on 2021/7/19.
//

import Foundation

extension NSMutableAttributedString {
    // MARK: - 同一给NSMutableAttributedString添加格式信息
    func addParagraphStyle(_ lineSpacing : CGFloat = 0, _ firstLineHeadIndent : CGFloat = 0, _ lineBreakModel : NSLineBreakMode = .byWordWrapping, _ font : UIFont, kern : Float = 0, alignment : NSTextAlignment = .left) -> NSMutableAttributedString {
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = lineSpacing
        paragraphStyle.lineBreakMode = .byWordWrapping;
        paragraphStyle.firstLineHeadIndent = firstLineHeadIndent
        paragraphStyle.alignment = alignment
        let attributes : [NSAttributedString.Key : Any] = [.font : font, .paragraphStyle : paragraphStyle, .kern : kern]
        addAttributes(attributes, range: NSRange(location: 0, length: length))
        return self
    }
}
